$(document).ready(function(){
	picChange();
	PickFunction();
	closeLeave()
	isLogin()
});

/**
 * 反馈
 */

$(document).on('click','.feedback_buttom',function(){
	var contactContent = $('.contactContent').val()
	var contactPerson = $('.contactPerson').val()
	var contactPhone = $('.contactPhone').val()

	if ( !contactContent ){

		$('.popup').html('请输入联系内容')
		$('.popup').show()
		var timer = setTimeout(function() {
			$('.popup').hide()
		}, 2000);
		// layer.msg('请输入联系内容');
		return false
	}
	if ( !contactPerson ){
		$('.popup').html('请输入联系人')
		$('.popup').show()
		var timer = setTimeout(function() {
			$('.popup').hide()
		}, 2000);
		// layer.msg('请输入联系人');
		return false
	}
	if ( !contactPhone ){
		$('.popup').html('请输入联系方式')
		$('.popup').show()
		var timer = setTimeout(function() {
			$('.popup').hide()
		}, 2000);
		// layer.msg('请输入联系方式');
		return false
	}

	var data = {
		message:contactContent,
		name:contactPerson,
		contact_way:contactPhone,
	}
	$.ajax({
		dataType : "json",
		type : "post",
		url : basePath+"/saveFeedbackMsg",
		data : JSON.stringify(data),
		contentType : "application/json",
		success : function(data) {
			if ( data.respCode == 1 ){
				$('.popup').html('提交成功！')
				$('.popup').show()
				var timer = setTimeout(function() {
					$('.popup').hide()
				}, 2000);
				$('.contactContent').val('')
				$('.contactPerson').val('')
				$('.contactPhone').val('')
				$('.allside_tooltip .content').hide()
				$('.leave_last_content').show()
			}
		}
	})
})

/**
 * 反馈
 */
var closeLeave = function(){
	$('.leave_last_content').on('click',' .button',function(){
		$('.allside_tooltip .content').show()
		$('.leave_last_content').hide()
		$('.allside_tooltip').addClass('hidden')
		setTimeout(function(){
			$('.allside_tooltip').removeClass('hidden')
		},1000)
	})
}

//鼠标移动至icon上icon边换图片
var picChange = function(){

	$(".allside_main_ser").on('click',function(){
		$('.ntalk-window-containter').show()
		$('.ntalk-minimize-window').click()
		// $('.nTalk-hidden-element').show()
	});


}
//鼠标点击icon效果
var PickFunction = function(){
	imgbside=basePath+"/static/pcsofangche/common/allside/img/";
	
	$("[data-toggle='tooltip']").tooltip();
	var p0="400-800-7278";
	$("a.allside_main_phone_a").attr('title',p0).tooltip('fixTitle');
	var p2="<img src=\""+imgbside+"allside_show_weixin.jpg\" class=\"allside_show_posi\">";
	$("a.allside_main_weixin_a").attr('title',p2).tooltip('fixTitle');
	var p3 = "service@sofangche.com";
	$("a.allside_main_email_a").attr('title',p3).tooltip('fixTitle');
}

/**
 * 判断是否登录
 */
function isLogin(){
	$.ajax({
		dataType : "json",
		type : "post",
		url : basePath+"/meb/checklogin",
		data : {
			
		},
		contentType : "application/x-www-form-urlencoded;charset=utf-8",

		success : function(data) {
			if(data.code == "1"){
				//点击会员
				//
				getAjax('/my/checkBindStatus',function(res){
					if(res.respCode == 1){
						$("div.allside_main_login").click(function(){
							var url = basePath+"/myorderlist?type=myCenter";
							url = encodeURI(url);
							url = encodeURI(url);
							window.location.href = (url);
						});
					}else{
						$("div.allside_main_login").click(function(){
							var url = basePath+"/mycenter";
							url = encodeURI(url);
							url = encodeURI(url);
							window.location.href = (url);
						});
					}
				})

				
			}else{
				//点击会员
				$("div.allside_main_login").click(function(){
					var url = basePath+"/loginstepone?loginstepflag=5";
					url = encodeURI(url);
					url = encodeURI(url);
					window.location.href = (url);
				});
			}
		},
		error : function() {
			console.log("访问失败");
		},
		complete : function() {
			console.log("请求完成");
		},
	});
}


function getAjax (url,fn){
	$.ajax({
	  dataType : "json",
      url: basePath + url,
      type: 'GET',
      xhrFields: {
        withCredentials: true
      },
      contentType : "application/json",
      success: function(res) {
      	if ( fn ){
      		fn(res)
      	}
      }
    })		
}
		


